/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bice.entity;

import com.bice.dao.IEntity;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.*;

/**
 *
 * @author sirius
 */
@Entity
@Table(name="Chat")
public class Chat implements IEntity {
    
    private Integer id;
    private String code;
    private String comment;
    private Chat parent;
    private Date created;
    private User user;
    
    private List<Chat> children = new ArrayList<Chat>();
    
    public Chat() {
    }
    
    @Id
    @GeneratedValue(strategy=IDENTITY)
    @Column(name="id", unique=true, nullable=false)
    public Integer getId() {
        return this.id;
    }
    
    public void setId(Integer id) {
        this.id = id;
    }
    
    @Column(name="code", nullable=false, length=32)
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
    
    @Column(name="comment", nullable=false, length=540)
    public String getComment() {
        return comment;
    }
    
    public void setComment(String comment) {
        this.comment = comment;
    }
    
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="parent")
    public Chat getParent() {
        return parent;
    }
    
    public void setParent(Chat parent) {
        this.parent = parent;
    }
    
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="user")
    public User getUser() {
        return user;
    }
    
    public void setUser(User user) {
        this.user = user;
    }
    
    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="parent")
    public List<Chat> getChildren() {
        return children;
    }
    
    public void setChildren(List<Chat> children) {
        this.children = children;
    }

    @Column(name="created", nullable=false)
    @Temporal(TemporalType.TIMESTAMP)
    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }
    
    
    
}